
define(function(require){
	var $=require("jq.js");
	
	//热门品牌------------------->
	var categoryBar = $("#js-hot-brand .category-bar div"),
		categoryCon = $("#js-hot-brand .category-con>div");
	
	categoryBar.mouseover(function(){
		
		var self   = $(this),
			index  = self.index();
		
		var intoCon = categoryCon.eq(index);
		this.timer = window.setTimeout(function(){
			if(!self.hasClass("selected")){
				
				self.addClass("selected").siblings().removeClass("selected");
				intoCon.addClass("show").siblings().removeClass("show");
				
			};
		},300);

	}).mouseout(function(){
		window.clearTimeout(this.timer);
	});
	
	//楼层里的品牌滑动组件------------->
	
	var smallSlider = function(slide){
		
		var slide = slide,
			ul    = slide.find(".slide-main ul"),
			lis   = ul.find("li"),
			size  = lis.size();
		
		if(size>1){
			var controlBtns = '<div class="small-slide-control">';
			ul.width(155*size);
			
			$(lis).each(function(i,o){
				
				if(i==0){
					controlBtns += "<span class='selected'></span>";
		
				}else{
					controlBtns += "<span></span>";
				};
				
			});
			controlBtns+="</div>";
			//把按钮插入
			slide.append(controlBtns);
			
			//绑定事件
			var btns = slide.find(".small-slide-control span"),
				btnSize = btns.size(),
				loop = 0,
				btnTimer = null;
			btns.mouseover(function(e){
				
				e.stopPropagation();
				
				var self = $(this),
					idx = self.index();
				loop = idx;
				if(!self.hasClass("selected")){
					
					self.addClass("selected").siblings().removeClass("selected");
					ul.stop().animate({marginLeft:-155*idx});
				};

			});
			
			//增加自动播放功能
			btnTimer = window.setInterval(function(){
				loop ++;
				if(loop >= btnSize){
					loop = 0;
				};
				btns.eq(loop).mouseover();
			},5000);
			
			
			slide.hover(function(){
				
				window.clearInterval(btnTimer);
				
			},function(){
				btnTimer = window.setInterval(function(){
					loop ++;
					if(loop >= btnSize){
						loop = 0;
					};
					btns.eq(loop).mouseover();
				},5000);
			});
			
		};
	
	};
	
	$(function(){
		$(".js-small-slide").each(function(){
			smallSlider($(this));
		});
	});

});